/**
 * @file testCSV.c
 * @brief 用于BookType的单元测试
 * @version 0.1
 * @date 2022-05-13
 *
 * @copyright Copyright (c) 2022
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include "../include/ListType.h"
#include "../include/BookType.h"
#include "../include/StrFunc.h"
int main()
{
    BookListType *bookList = BookListType_BookListType("./书本.csv");
    printf("输入一行关键词：");
    char *patt = Str_lineFromStdin();
    ListType *subList = BookListType_query(bookList, patt);
    if (subList->size)
    {
        BookType *book = BookType_ListNode(subList->head);
        if (book->currentQuantity)
        {
            printf("%s %d/%d 借出一本\n", book->title, book->currentQuantity, book->totalQuantity);
            book->currentQuantity--;
            printf("%s %d/%d\n", book->title, book->currentQuantity, book->totalQuantity);
        }
        else
        {
            printf("%s %d/%d 已经全部借出\n", book->title, book->currentQuantity, book->totalQuantity);
        }
    }
    else
    {
        printf("没有关于\"%s\"的书\n", patt);
    }
    BookListType_write(bookList);

    free(patt);
    BookListType_free(bookList);
    return 0;
}
